package edu.uwlax.cs.oayonlinestore.client.gui.salesdept;

import com.google.gwt.user.client.ui.Hyperlink;

import edu.uwlax.cs.oayonlinestore.client.OnlinestoreRService;
import edu.uwlax.cs.oayonlinestore.client.gui.Store;
import edu.uwlax.cs.oayonlinestore.client.utils.DekoTable;
import edu.uwlax.cs.oayonlinestore.client.utils.TitlePage;
import edu.uwlax.cs.oayonlinestore.vo.RetExFormVO;

public class PageSalListRetexForms extends TitlePage {

	private class RetexTable extends DekoTable {

		public RetexTable() {
			super();
			String anchor = Store.getFrame().getSalOrders().getAnchor(0);
			addTitle("Date");
			addTitle("Customer");
			addTitle("Brand");
			addTitle("Product");
			addTitle("#");
			addTitle("Status");
			addTitleWidget(new Hyperlink("add", anchor));
		}

		public void addItem(RetExFormVO form) {
			String anchror = Store.getFrame().getSalRetex().getAnchor(false,
					form.getId());
			AddRow r = addRow();
			r.add(form.getDate() + "");
			r.add(form.getUser().getFirstname() + " "
					+ form.getUser().getLastname());
			r.add(form.getOrderItem().getProduct().getBrand());
			r.add(form.getOrderItem().getProduct().getName());
			r.add(form.getQuantity());
			r.add(form.getStatus());
			r.add(new Hyperlink("edit", anchror));
		}
	}

	private RetexTable table;

	protected void create() {
		setTitle("Return/Exchange Forms");
		add(table = new RetexTable());
	}

	public String getID() {
		return "ListRetexForms";
	}

	protected void onDataArrived(Object o) {
		RetExFormVO[] a = (RetExFormVO[]) o;
		table.cleanExceptHeader();
		for (int i = 0; i < a.length; i++)
			table.addItem(a[i]);
	}

	protected void onShow() {
		OnlinestoreRService.Util.getInstance().getRetExFormsList(
				getAsyncHandler());
	}

}
